package edu.siu.math.egut.egut;


/**
 * Class representing a LiE vector.
 * 
 * @author Joe Pleso
 *
 */
public class LiEVector extends AbstractLiEObject {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private final int[] result;
    
    
    /**
	 * Converts LiE row vector output into an int[].
	 * 
	 * @param s row vector from LiE
	 * 
	 */
    public LiEVector (String s){
	super(LiEType.VEC);
	
	s =  s.trim();
	s = s.substring(1, s.length() - 1);
	
	String[] values = s.split(Character.toString(Algorithms.LIE_COMMA));
	
	
	result = new int[values.length];
	for (int i = 0; i < values.length; i++){
	    result[i] = Integer.parseInt(values[i]);
	}
	
	
    }
    
    /**
     * Wraps a java array into a LiEVector
     * 
     * @param r java array of ints
     */
    public LiEVector (int[] r){
	super(LiEType.VEC);
	result = r;
    }
    
    
    public Object getJavaObject() {
	return result;
    }
    
    
    /**
	 * Convert a int[] into a string that LiE will parse as a
	 * vector.
	 * 
	 * 
	 * @return a string representing a LiE vector
	 */
    public String toString(){
	StringBuffer sb = new StringBuffer();
	    sb.append(Algorithms.LIE_LEFT_SQUARE_BRACKET);
	    for (int i = 0; i < result.length; i++){
		sb.append(result[i]);sb.append( Algorithms.LIE_COMMA);}
	    sb.setCharAt(sb.length() - 1, Algorithms.LIE_RIGHT_SQUARE_BRACKET);
	    return sb.toString();
    }
    
	
	
}
